<?php
namespace app\api\controller\Meta;
use support\exception\ValidateException;
use app\api\controller\CommonController;
use think\facade\Db;

class WebController extends CommonController{



	/**
	 *@description 查看详情
	 *@buildcode(false)
	*/
	function detail(){
		$postField = 'meta_id';
		$data = $this->request->only(explode(',',$postField),'post');

		if(empty($data['meta_id'])){
				throw new ValidateException ('meta_id不能为空');
		}
		$meta_res = Db::name('meta_web')
								->alias('meta')
								->field('meta.name as meta_name, meta.ttsType_id as ttsType_id,stt.type as stt_type, tts.type as tts_type, role.action_ids as action_ids ,role.model_ids as model_ids , chat.type as chat_type')  // 选择需要查询的字段，可以使用别名来区分不同表中相同字段名
								->join('cd_typestt stt', 'meta.sttType_id = stt.typestt_id', 'LEFT')
								->join('cd_typetts tts', 'meta.ttsType_id = tts.typetts_id', 'LEFT')
								->join('cd_chat chat', 'meta.chat_id = chat.chat_id', 'LEFT')
								->join('cd_meta_web_role role', 'meta.modelrole_id = role.role_id', 'LEFT')
								->where('meta_id',$data['meta_id'])
								->find();
								// ->join('cd_webmodel webmodel', 'FIND_IN_SET(webmodel.webmodel_id, role.model_ids)', 'LEFT')
								// ->join('cd_modelaction modelaction', 'FIND_IN_SET(modelaction.modelaction_id, role.action_ids)', 'LEFT')
		
		if($meta_res == null)
		{
				return json(['status'=>400,'msg'=>'meta not found']);
		}

		$actions = Db::name("modelaction")
														->field("name,img,model,type")
														->where("status",1)
														->where("modelaction_id", 'IN' , $meta_res["action_ids"])
														->select();

		$models = Db::name("webmodel")
														->field("name,img,model")
														->where("status",1)
														->where("webmodel_id", 'IN' , $meta_res["model_ids"])
														->order("weight", "DESC")
														->select();

		$voice = Db::name("tts_voice")
														->field("name,value,sex")
														->where("status",1)
														->where("tts_id" , $meta_res["ttsType_id"])
														->order("weight", "DESC")
														->select();

		unset($meta_res["action_ids"]);
		unset($meta_res["model_ids"]);

		$meta_res["models"] = $models;
		$meta_res["actions"] = $actions;
		$meta_res["voices"] = $voice;

		return json(['status'=>200,'data'=>$meta_res]);
	}


}